package gcu.module.property_apply.rest;

import gcu.module.property_apply.daomain.PropertyApply;
import gcu.module.property_apply.service.ApplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * Created by haol on 2016/9/24.
 */
@RestController
@RequestMapping("/rest/apply")
public class ApplyRestController {

      @Autowired
      private ApplyService applyService;

      @RequestMapping(value = "/get", method = RequestMethod.GET)
      public Map<String, Object> get(Integer id) {
            return applyService.get(id);
      }

      @RequestMapping(value = "/save", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
      public boolean save(@RequestBody PropertyApply apply) {
            if (apply.getId() == null){
                  applyService.add(apply);
            }else {
                  applyService.update(apply);
            }
            return true;
      }
      @RequestMapping(value = "/checkIsHandle", method = RequestMethod.POST)
      public boolean check() {
            List<PropertyApply> applies = applyService.getNotHandle();
            if (applies.size() == 0){
                  return false;
            }else {
                  return true;
            }
      }
}
